package com.study.security.core.social.weixin.config;

import com.study.security.core.properties.SecurityProperties;
import com.study.security.core.properties.WeiXinProperties;
import com.study.security.core.social.SocialAutoConfigurerAdapter;
import com.study.security.core.social.weixin.connect.WeiXinConnectFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;
import org.springframework.social.connect.ConnectionFactory;

/**
 * @author liyongkui
 */
@Configuration
@ConditionalOnProperty(prefix = "security.social.weixin",name = "appId")
public class WeiXinAutoConfig extends SocialAutoConfigurerAdapter {

    @Autowired
    private SecurityProperties securityProperties;

    @Override
    protected ConnectionFactory<?> createConnectionFactory() {
        WeiXinProperties weiXinConfig = securityProperties.getSocial().getWeixin();
        return new WeiXinConnectFactory(weiXinConfig.getProviderId(), weiXinConfig.getAppId(),
                weiXinConfig.getAppSecret());
    }
}
